Code:
var board = new TRUGameBoard(SIZE, SIZE, "borderLine", 400, 400, "LightGrey");
board.draw('game-board'); // 'game-board' is the id of an <div> in which the game board is displayed.
// Event handler registration for mouse 'click'
board.cellsEventListener('click', function(e) {
var pos = board.position(e); // pos: {row:r, col:c}
// Person
// If there is not 'X' or 'O' mark, i.e., not occupied
if (board.cellContent(pos.row, pos.col) != 'X' && board.cellContent(pos.row, pos.col) != 'O' ) {
ttt_mark(board, pos.row, pos.col, 'X', X_O_SIZE); // Mark the cell with 'X'
// Now computer's turn
ttt_computer_turn(board, X_O_SIZE);
}
});
// For coloring on the mouse movement
board.cellsEventListener('mouseenter', function(e) {
var pos = board.position(e);
var current_color = board.cellBackgroundColor(pos.row, pos.col);
board.cellMark2(pos.row, pos.col, current_color);
board.cellBackgroundColor(pos.row, pos.col, 'LightSteelBlue');
});
board.cellsEventListener('mouseleave', function(e) {
var pos = board.position(e);
var previous_color = board.cellMark2(pos.row, pos.col);
board.cellBackgroundColor(pos.row, pos.col, previous_color);
});